package sgi.client;

import java.awt.BorderLayout;
import sgi.message.MessageChangeTariff;
import javax.swing.JOptionPane;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import sgi.user.User;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.IOException;

public class SGIUserAccountMenuUI extends SGIClientFrame  {

	private JPanel contentPane;
	private SGIUserAccountMenuController menu;
	
	public SGIUserAccountMenuUI(User user)
	{
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 601, 425);
		contentPane = new JPanel();
		contentPane.setLayout(null);
		setContentPane(contentPane);
		setTitle("SGI-"+user.getUsername());
		
	        
		switch(user.getPrivilege())
		{
			case 1:
			{
				JButton btnSearchArchive = new JButton("Search Archive");
				btnSearchArchive.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						try {
							SGISearchArchiveController.create();
						} catch (IOException e) {
							e.printStackTrace();
						}
						SGIUserAccountMenuController.terminate();
					}
				});
				btnSearchArchive.setBounds(10, 11, 180, 23);
				contentPane.add(btnSearchArchive);
		
				JButton btnInteractiveMap = new JButton("Interactive Map");
				btnInteractiveMap.setBounds(10, 47, 180, 23);
				contentPane.add(btnInteractiveMap);
				btnInteractiveMap.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						try {
							SGIInteractiveMapController.create();
							SGIUserAccountMenuController.terminate();
						} catch (IOException e1) {
							e1.printStackTrace();
						}
					}
				});
		
				JButton btnPurchasedImages = new JButton("Purchased Images");
				btnPurchasedImages.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						try {
							SGIWatchPurchasedImagesController.create();
							SGIUserAccountMenuController.terminate();
						} catch (IOException e1) {
							e1.printStackTrace();
						}
					}
				});
				btnPurchasedImages.setBounds(10, 81, 180, 23);
				contentPane.add(btnPurchasedImages);
				
				JButton btnCompaint = new JButton("File a complaint");
				btnCompaint.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						try {
							SGIComplaintController.create(SGIUserAccountMenuController.create(null).getUser());
							SGIUserAccountMenuController.terminate();
						} catch (IOException e1) {
							e1.printStackTrace();
						}
					}
				});
				btnCompaint.setBounds(10, 115, 180, 23);
				contentPane.add(btnCompaint);
		
				JButton btnAccountInfo = new JButton("Account Info");
				btnAccountInfo.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						try{
							
							SGIAccountInfoController.create(SGIUserAccountMenuController.create(null).getUser());
							SGIAccountInfoController.getUI().review();
							SGIAccountInfoController.accountInfo.getHistory();
							SGIUserAccountMenuController.terminate();
						}catch (IOException e1) {e1.printStackTrace();}
					}
				});
				btnAccountInfo.setBounds(10, 148, 180, 23);
				contentPane.add(btnAccountInfo);
		
				JButton btnSubscriptions = new JButton("Purchase Subscription");
				btnSubscriptions.addActionListener(new ActionListener()
				{
					public void actionPerformed(ActionEvent arg0)
					{
						SGIUserAccountMenuController.terminate();
						SGISubscribeController.createSubscribe();
					}
				});
				btnSubscriptions.setBounds(10, 184, 180, 23);
				contentPane.add(btnSubscriptions);
				
				JButton btnMessage = new JButton("Messages");
				btnMessage.addActionListener(new ActionListener()
				{
					public void actionPerformed(ActionEvent arg0)
					{
						SGIUserAccountMenuController.terminate();
						try {
							SGIMessagesController.create();
							SGIMessagesController.getUI().review();
						} catch (IOException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
				});
				btnMessage.setBounds(10, 220, 180, 23);
				contentPane.add(btnMessage);
				
				JButton btnReviewTariff = new JButton("Review Tariffs");
				btnReviewTariff.addActionListener(new ActionListener()
				{
					public void actionPerformed(ActionEvent arg0)
					{
						SGIUserAccountMenuController.terminate();
						try {
							SGIViewTariffController.create();
							SGIViewTariffController.getUI().review();
						} catch (IOException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
				});
				btnReviewTariff.setBounds(10, 268, 180, 23);
				contentPane.add(btnReviewTariff);
				
				
				
				
				JButton btnLogoff = new JButton("Logoff");
				btnLogoff.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e)  {
						try {
							SGILoginController login = SGILoginController.createLogin();
							login.logoff(menu.getUser());
						} catch (IOException e1) {e1.printStackTrace();}
					}
				});
				btnLogoff.setBounds(456, 353, 89, 23);
				contentPane.add(btnLogoff);
			}break;
			
			case 2:
			{
				JButton btnComplaintReview = new JButton("Review Complaints");
				btnComplaintReview.setBounds(10, 11, 180, 23);
				contentPane.add(btnComplaintReview);
				btnComplaintReview.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e)  {
						try {
							SGIUserAccountMenuController.terminate();
							SGIComplaintReviewController.create();
							SGIComplaintReviewController.getUI().review();
						} catch (IOException e1) {e1.printStackTrace();}
					}
				});				
				
				JButton btnLogoff2 = new JButton("Logoff");
				btnLogoff2.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e)  {
						try {
							SGILoginController login = SGILoginController.createLogin();
							login.logoff(menu.getUser());
						} catch (IOException e1) {e1.printStackTrace();}
					}
				});
				btnLogoff2.setBounds(456, 353, 89, 23);
				contentPane.add(btnLogoff2);
							
			}break;
			
			case 3:
			{
				JButton btnRegister = new JButton("Register Accounts");
				btnRegister.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						SGIUserAccountMenuController.terminate();
						SGIRegisterController.createRegister();
					}
				});
				btnRegister.setBounds(10, 11, 180, 23);
				contentPane.add(btnRegister);
				
				JButton btnReviewSubscribe = new JButton("Subscribe Accounts");
				btnReviewSubscribe.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						try {
							SGIUserAccountMenuController.terminate();
							SGIReviewSubscriptionsController.createSubscriptions();
							SGIReviewSubscriptionsController.getUI().review();
						} catch (IOException e) {
							e.printStackTrace();
						}
					}
				});
				btnReviewSubscribe.setBounds(10, 47, 180, 23);
				contentPane.add(btnReviewSubscribe);
			
			

			
				JButton btnLogoff3 = new JButton("Logoff");
				btnLogoff3.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e)  {
						try {
							SGILoginController login = SGILoginController.createLogin();
							login.logoff(menu.getUser());
						} catch (IOException e1) {e1.printStackTrace();}
					}
				});
				btnLogoff3.setBounds(456, 353, 89, 23);
				contentPane.add(btnLogoff3);
					
			}break;
				
			case 4:
			{
				JButton btnUpdatedPrices = new JButton("Updated Prices");
				btnUpdatedPrices.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						SGIUserAccountMenuController.terminate();
						SGITariffController.create();
					}
				});
				btnUpdatedPrices.setBounds(10, 11, 180, 23);
				contentPane.add(btnUpdatedPrices);
				
				JButton btnMonthlyReport = new JButton("Monthly Report");
				btnMonthlyReport.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						SGIUserAccountMenuController.terminate();
						SGICreateReportsController.create();
					}
				});
				btnMonthlyReport.setBounds(10, 47, 180, 23);
				contentPane.add(btnMonthlyReport);		

					
				JButton btnLogoff4 = new JButton("Logoff");
				btnLogoff4.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e)  {
						try {
							SGILoginController login = SGILoginController.createLogin();
							login.logoff(menu.getUser());
						} catch (IOException e1) {e1.printStackTrace();}
					}
				});
				btnLogoff4.setBounds(456, 353, 80, 23);
				contentPane.add(btnLogoff4);
			}break;
				
			case 5:
			{
				JButton btnWeeklyReport = new JButton("Check Reports");
				btnWeeklyReport.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						SGIUserAccountMenuController.terminate();
						SGICheckReportsController.create();
					}
				});
				btnWeeklyReport.setBounds(10, 11, 180, 23);
				contentPane.add(btnWeeklyReport);
				
//				JButton btnYearReport = new JButton("Year Report");
//				btnYearReport.addActionListener(new ActionListener() {
//					public void actionPerformed(ActionEvent arg0) {
//					}
//				});
//				btnYearReport.setBounds(10, 47, 180, 23);
//				contentPane.add(btnYearReport);
				
				JButton btnApproveORDecline = new JButton("Approve/Decline");
				btnApproveORDecline.addActionListener(new ActionListener()
				{
					public void actionPerformed(ActionEvent arg0)
					{
						SGIUserAccountMenuController.terminate();
						SGICEOTariffController.create();
						
					}
				});
				btnApproveORDecline.setBounds(10, 81, 180, 23);
				contentPane.add(btnApproveORDecline);
				
				JButton btnLogoff5 = new JButton("Logoff");
				btnLogoff5.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e)  {
						try {
							SGILoginController login = SGILoginController.createLogin();
							login.logoff(menu.getUser());
						} catch (IOException e1) {e1.printStackTrace();}
					}
				});
				btnLogoff5.setBounds(456, 353, 89, 23);
				contentPane.add(btnLogoff5);
			}break;
			
			case 6:
			{
				
				JButton btnAddImage = new JButton("Add Image");
				btnAddImage.addActionListener(new ActionListener()
				{
					public void actionPerformed(ActionEvent arg0)
					{
						SGIUserAccountMenuController.terminate();
						try {
							SGIImageAddController.create();
						} catch (IOException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
				});
				btnAddImage.setBounds(10, 11, 180, 23);
				contentPane.add(btnAddImage);
				
				JButton btnEditImage = new JButton("Edit Image");
				btnEditImage.addActionListener(new ActionListener()
				{
					public void actionPerformed(ActionEvent arg0)
					{
						SGIUserAccountMenuController.terminate();
						try {
							SGIImageEditController.create();
						} catch (IOException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						SGIImageEditController.getUI().review();
					}
				});
				btnEditImage.setBounds(10, 47, 180, 23);
				contentPane.add(btnEditImage);
				
				JButton btnDeleteImage = new JButton("Delete Image");
				btnDeleteImage.addActionListener(new ActionListener()
				{
					public void actionPerformed(ActionEvent arg0)
					{
						SGIUserAccountMenuController.terminate();
						try {
							SGIImageDeleteController.create();
						} catch (IOException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						SGIImageDeleteController.getUI().review();
						
						
					}
				});
				btnDeleteImage.setBounds(10, 81, 180, 23);
				contentPane.add(btnDeleteImage);
	
				
				JButton btnLogoff6 = new JButton("Logoff");
				btnLogoff6.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e)  {
						try {
							SGILoginController login = SGILoginController.createLogin();
							login.logoff(menu.getUser());
						} catch (IOException e1) {e1.printStackTrace();}
					}
				});
				btnLogoff6.setBounds(456, 353, 89, 23);
				contentPane.add(btnLogoff6);
			}break;
			
			case 7:
			{
				JButton btnAddImage = new JButton("Add Image");
				btnAddImage.addActionListener(new ActionListener()
				{
					public void actionPerformed(ActionEvent arg0)
					{
						SGIUserAccountMenuController.terminate();
						try {
							SGIImageAddController.create();
						} catch (IOException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
				});
				btnAddImage.setBounds(10, 11, 180, 23);
				contentPane.add(btnAddImage);
				
				JButton btnEditImage = new JButton("Edit Image");
				btnEditImage.addActionListener(new ActionListener()
				{
					public void actionPerformed(ActionEvent arg0)
					{
						SGIUserAccountMenuController.terminate();
						try {
							SGIImageEditController.create();
						} catch (IOException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						SGIImageEditController.getUI().review();
					}
				});
				btnEditImage.setBounds(10, 47, 180, 23);
				contentPane.add(btnEditImage);
				
				JButton btnDeleteImage = new JButton("Delete Image");
				btnDeleteImage.addActionListener(new ActionListener()
				{
					public void actionPerformed(ActionEvent arg0)
					{
						SGIUserAccountMenuController.terminate();
						try {
							SGIImageDeleteController.create();
						} catch (IOException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						SGIImageDeleteController.getUI().review();
						
						
					}
				});
				btnDeleteImage.setBounds(10, 81, 180, 23);
				contentPane.add(btnDeleteImage);

				
				
				JButton btnLogoff7 = new JButton("Logoff");
				btnLogoff7.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e)  {
						try {
							SGILoginController login = SGILoginController.createLogin();
							login.logoff(menu.getUser());
						} catch (IOException e1) {e1.printStackTrace();}
					}
				});
				btnLogoff7.setBounds(456, 353, 89, 23);
				contentPane.add(btnLogoff7);				
			}break;
		}
	}
	

	public SGIUserAccountMenuController getMenu() {
		return menu;
	}

	public void setMenu(SGIUserAccountMenuController menu) {
		this.menu = menu;
	}



}
